package com.hellpro.lolbox.video.model;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.hellpro.lolbox.R;
import com.hellpro.lolbox.video.bean.VideoHotBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 类描述:
 * 创建人:阿犇
 * 创建时间:2016/10/20
 * 备注:
 */

public class VideoHotLvAdapter extends BaseAdapter {


    private List<VideoHotBean> mList;

    public VideoHotLvAdapter() {

    }

    public void setData(List<VideoHotBean> list) {
        this.mList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList != null ? mList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mList != null ? mList.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.video_hot_list_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        VideoHotBean videoHotBean = mList.get(position);

        holder.videoHotItemIvShow.setImageURI(Uri.parse(videoHotBean.getPic_url()));
        holder.videoHotItemTvTitle.setText(videoHotBean.getTitle());
        holder.videoHotItemTvTime.setText(videoHotBean.getDesc());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.video_hot_item_ivShow)
        SimpleDraweeView videoHotItemIvShow;
        @BindView(R.id.video_hot_item_tvTitle)
        TextView videoHotItemTvTitle;
        @BindView(R.id.video_hot_item_tvTime)
        TextView videoHotItemTvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
